home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
os2tools
/
bnklysrc
/
cdog.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-03-31
|
16KB
|
564 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software <no-Inc> */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / No-Cost<no-tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
/* */
/* */
/* This module was written by Bob Hartman */
/* */
/* BinkleyTerm SEAdog Mail Session Routines */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
/* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
/* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
/* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
/* ARE ABLE TO REACH WITH THE AUTHORS. */
/* */
/* */
/* The Authors can be reached at the following addresses: */
/* */
/* Robert C. Hartman Vincent E. Perriello */
/* Spark Software VEP Software */
/* 427-3 Amherst Street 111 Carroll Street */
/* CS2032, Suite 232 Naugatuck, CT 06770 */
/* Nashua, NH 03061 */
/* */
/* FidoNet 1:132/101 FidoNet 1:141/491 */
/* Data (603) 888-8179 Data (203) 729-7569 */
/* */
/* Please feel free to contact us at any time to share your comments */
/* about our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <signal.h>
#include <ctype.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#define WAZOO_SECTION
#define MATRIX_SECTION
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
#define rb_plus "rb+"
static int req_out (char *, char *, char *);
static int get_req_str (char *);
static void gen_req_name (char *);
static int cdog_callback(char *);
static int need_to_send_ACK;
void SEA_sendreq ()
{
char fname[80];
char reqf[80];
char *reqtime = " 0";
char *p, *name, *pw;
char *updtime;
int i, j, done, done1, nfiles;
FILE *fp;
long t1;
char *HoldName;
t1 = timerset (1000);
HoldName = HoldAreaNameMunge(called_zone);
sprintf (fname,
"%s%04x%04x.REQ",
HoldName, called_net, called_node);
errno = 0;
/* If we have file requests, then do them */
if (!dexists (fname))
{
status_line (":No outgoing file requests");
}
else
{
status_line (":Outbound file requests");
/* Open the .REQ file */
if ((fp = fopen (fname, "r")) == NULL)
{
SENDBYTE (ETB);
return;
}
/* As long as we do not have EOF, read the request */
while ((fgets (reqf, 79, fp) != NULL) && (CARRIER))
{
/* Properly format the request */
/* First get rid of the trailing junk */
p = reqf + strlen (reqf) - 1;
while ((p >= reqf) && (isspace (*p)))
*p-- = '\0';
/* Now get rid of the beginning junk */
p = reqf;
while ((*p) && (isspace (*p)))
p++;
/* This is where the name starts */
name = p;
/* If the first char is ; then ignore the line */
if (*name == ';')
continue;
/* Now get to where the name ends */
while ((*p) && (!isspace (*p)))
p++;
updtime = reqtime; /* Default to request */
pw = p; /* This is or will be a null */
req_scan:
if (*p)
{
*p++ = '\0';
while ((*p) && (*p != '!') && (*p != '-') && (*p != '+'))
p++;
/* Check for a password */
if (*p == '!')
{
*p = ' ';
pw = p++;
/* Now get to where the password ends */
while ((*p) && (!isspace (*p)))
p++;
goto req_scan;
}
/* Try for an update request */
if (*p == '+')
{
*p = ' ';
updtime = p++;
/* Now get to where the update time ends */
while ((*p) && (!isspace (*p)))
p++;
*p = '\0';
/* Request time is last thing we care about on line, so
we just drop out of the loop after finding it.
*/
}
/* Note: since SEAdog doesn't do "backdate" requests, all we
have to do if we see a '-' is to do a full request. Hence
we only process a '+' here.
*/
}
if (req_out (name, pw, updtime))
continue;
/* Wait for ACK or ENQ */
t1 = timerset (6000);
done = 0;
while ((!timeup (t1)) && CARRIER && !done)
{
j = TIMED_READ (0);
if (j >= 0)
{
if (j == ACK)
{
/* If ACK, receive files using SEAlink */
nfiles = 0;
done1 = 0;
do
{
if ((i = try_sealink ()) == 0)
{
if (!recvmdm7 (reqf))
{
done1 = 1;
}
else
{
if (!receive_file (CurrentNetFiles, NULL, 'T'))
{
if (locate_y > 1 && !(fullscreen && un_attended))
gotoxy (0, locate_y - 1);
done1 = 1;
}
else ++nfiles;
}
}
else if (i == 1)
{
if (!receive_file (CurrentNetFiles, NULL, 'F'))
{
if (locate_y > 1 && !(fullscreen && un_attended))
gotoxy (0, locate_y - 1);
done1 = 1;
}
else ++nfiles;
}
else
{
done1 = 1;
}
} while (CARRIER && !done1);
status_line (":Received %d files", nfiles);
done = 1;
t1 = timerset (6000);
/* wait for request start */
while ((TIMED_READ (0) != ENQ) && (!timeup (t1)) && CARRIER)
time_release ();
}
else if (j == ENQ)
{
/* If ENQ, report no files received */
req_out (name, pw, updtime);
}
else
{
time_release ();
if (!j)
t1 = timerset (6000);
}
}
}
}
fclose (fp);
unlink (fname);
status_line (":End of outbound file requests");
}
/* Finish the file requests off */
SENDBYTE (ETB);
}
int SEA_recvreq ()
{
int j;
int done = 0;
int nfiles = 0;
int nfiles1;
char req[64];
long t1, timerset ();
int n_frproc (char *, int, int (*)(char *));
t1 = timerset (2000);
if (no_requests)
{
/* Refuse file requests */
SENDBYTE (CAN);
status_line ("*Refusing inbound file requests");
return TRUE;
}
/* Try the bark stuff */
status_line (":Inbound file requests");
while (CARRIER && !done && (!timeup (t1)))
{
/* Send out the start signal */
SENDBYTE (ENQ);
/* Wait for the response */
j = TIMED_READ (2);
switch (j)
{
case ACK:
nfiles1 = nfiles;
if (get_req_str (req))
{
gen_req_name (req);
need_to_send_ACK = 1;
if (((nfiles = n_frproc (req, nfiles, cdog_callback)) < 0)
|| nfiles1 == nfiles)
{
SENDBYTE (ACK);
send_file (NULL, 'S');
}
else
status_line (":%d matching files sent", nfiles-nfiles1);
}
else
send_file (NULL, 'S');
if (nfiles < 0) /* Error returned from n_frproc */
done = 1; /* Should end request */
t1 = timerset (2000);
break;
case ETB:
case ENQ:
done = 1;
break;
case 'C':
case NAK:
SENDBYTE (EOT);
CLEAR_INBOUND ();
break;
}
}
status_line (":End of inbound file requests");
return TRUE;
}
int try_sealink ()
{
int i, j;
long t1, timerset ();
CLEAR_INBOUND ();
for (i = 0; i < 5; i++)
{
SENDBYTE ('C');
t1 = timerset (100);
while (!timeup (t1) && CARRIER)
{
if ((j = PEEKBYTE ()) >= 0)
{
if ((j == SOH) || (j == SYN))
return (1);
j = TIMED_READ (0);
if (j == EOT)
return (2);
else if (j == TSYNC)
return (0);
}
else
{
time_release ();
}
}
if (!CARRIER)
break;
}
return (0);
}
static int req_out (name, pw, updtime)
char *name, *pw, *updtime;
{
char *p;
unsigned int crc;
/* send the request */
p = name;
if (!*p)
return (1);
status_line ("*Requesting '%s' %s%s", name, (*pw) ? "with password" : "", pw);
SENDBYTE (ACK);
crc = 0;
while (*p)
{
SENDBYTE (*p);
crc = xcrc (crc, (byte) (*p));
++p;
}
/* Now send the update time */
p = updtime;
while (*p)
{
SENDBYTE (*p);
crc = xcrc (crc, (byte) (*p));
++p;
}
/* Finally the password */
p = pw;
while (*p)
{
SENDBYTE (*p);
crc = xcrc (crc, (byte) (*p));
++p;
}
SENDBYTE (ETX);
SENDBYTE ((unsigned char) (crc & 0xff));
SENDBYTE ((unsigned char) (crc >> 8));
return (0);
}
static int get_req_str (req)
char *req;
{
unsigned int crc, crc1, crc2, crc3;
int i, j;
crc = i = 0;
while (CARRIER)
{
j = TIMED_READ (2);
if (j < 0)
return (0);
if (j == ETX)
{
crc1 = TIMED_READ (2);
crc2 = TIMED_READ (2);
crc3 = (crc2 << 8) + crc1;
if (crc3 != crc)
{
status_line ("!Bad crc - trying again");
return (0);
}
req[i] = '\0';
SENDBYTE (NUL);
return (1);
}
else
{
req[i++] = (char) (j & 0xff);
crc = xcrc (crc, (j & 0xff));
}
}
return (0);
}
/*
* gen_req_name -- take the name [time] [password] fields from
* the BARK file request format and reformat to
* name [!password] [+time] WaZOO format for use
* by the WaZOO file request routines.
*
* Input: *req = pointer to character array with Bark string
* Output: *req array contents reformatted
*
*/
static void gen_req_name (req)
char *req;
{
char *q, *q1;
char buf[48];
char *fsecs = NULL;
q = req;
q1 = buf;
/* Get the filename */
while ((*q) && (!isspace (*q)))
{
*q1++ = *q++;
}
*q1 = '\0';
/* If we have more characters, go on */
if (*q)
{
/* Skip the space */
fsecs = q++;
*fsecs = '+';
/* Skip the digits */
while ((*q) && (!isspace (*q)))
q++;
/* If we have more, get the password */
if (*q)
{
*q++ = '\0'; /* Skip space, terminate the time */
*q1++ = ' ';
*q1++ = '!';
while (*q)
{
*q1++ = *q++;
}
*q1 = '\0';
}
/* If we got an update time */
if (fsecs != NULL)
{
*q1++ = ' ';
while (*fsecs)
{
*q1++ = *fsecs++;
}
*q1 = '\0';
}
}
strcpy (req, buf);
return;
}
static int cdog_callback(reqs)
char *reqs;
{
int i;
char p;
if (need_to_send_ACK)
{
SENDBYTE (ACK);
need_to_send_ACK = 0;
}
if (reqs[0])
i = xfermdm7 (reqs);
else i = 2;
p = 'T';
if (i == 0)
{
net_problems = 1;
return (0);
}
else if (i == 2)
p = 'F';
send_file (reqs, p);
return (1);
}